package cn.yitun.chat.yitunservermanagecore.general.manage.personal.controller;

import cn.yitun.chat.yituncommonmessage.result.ResultMessage;
import cn.yitun.chat.yitungeneral.annotation.codec.Encryped;
import cn.yitun.chat.yitungeneral.annotation.parameter.JsonDefine;
import cn.yitun.chat.yitungeneral.annotation.parameter.RequestParameter;
import cn.yitun.chat.yitunservercommonlib.basebean.web.JwtUserDto;
import cn.yitun.chat.yitunservercommonlib.crud.yitun.BaseController;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.system.user.ResetPwdDto;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.system.user.UserVo;
import cn.yitun.chat.yitunservermanagecore.general.bridge.auth.annotation.PermissionMapping;
import cn.yitun.chat.yitunservermanagecore.general.manage.personal.service.PersonalService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * date 2018-06-04 14:59:44<br>
 * description个人中心
 * 
 * @author yitun<br>
 * @since
 */
@RestController
@RequestMapping("/manage")
public class PersonalController extends BaseController{

	@Resource
	PersonalService personalService;

	@ResponseBody
	@RequestParameter
	@PermissionMapping(name = "个人信息", perms = "sys:user:info", isIntercept = false)
	@RequestMapping(method = RequestMethod.POST, value = "/personal/info")
	public Object user(JwtUserDto jwtUserDto) {
		ResultMessage rm = new ResultMessage();
		UserVo user = personalService.getUserVo(jwtUserDto.getUserId());
		rm.bodyPut("user", user);
		return rm;
	}

	@ResponseBody
	@RequestParameter
	@PermissionMapping(name = "修改密码", perms = "sys:user:update")
	@RequestMapping(method = RequestMethod.POST, value = "/personal/updatePassword")
	@Encryped(decode = true)
	public Object updatePassword(@JsonDefine ResetPwdDto resetPwdDto) {
		ResultMessage rm = personalService.updatePassword(resetPwdDto.getId(), resetPwdDto.getNewPassword(), resetPwdDto.getOldPassword());
		return rm;
	}

	@ResponseBody
	@RequestParameter
	@PermissionMapping(name = "更新用户密码等信息", perms = "sys:user:update")
	@Encryped(decode = true)
	@RequestMapping(method = RequestMethod.POST, value = "/personal/formatAllUserMag")
	public Object formatAllUserMag() {
		personalService.formatAllUserMag();
		return new ResultMessage();
	}
}
